﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DAL;

namespace BAL
{
    public class BAL_DangKy
    {
        QuanLyPhongTroDBDataContext dbs = new QuanLyPhongTroDBDataContext();

        public IQueryable ChuaDangKy()
        {
            var q1 = from v1 in dbs.KhachHangs
                       where ! (from v2 in dbs.DangKies
                                        select v2.CMND)
                                        .Contains(v1.CMND)
                       select v1;
            return q1;

        }
        public IQueryable DaDangKy()
        {
            var q2 = from v1 in dbs.KhachHangs
                     join v2 in dbs.DangKies
                     on v1.CMND equals v2.CMND
                     select new {v1.CMND,v1.TenKH,v2.MaPhong,v2.NgayDK,v2.NgayDi };
            return q2;
        }
        public void ThemDangKy(string _cmnd, DateTime _ngayDK, DateTime _ngayDi, string _maPhong)
        {
            DangKy _dangKy = new DangKy()
            {
                CMND=_cmnd,
                NgayDK=_ngayDK,
                NgayDi=_ngayDi,
                MaPhong=_maPhong
            };
            dbs.DangKies.InsertOnSubmit(_dangKy);
            dbs.SubmitChanges();
        }

        public void XoaDangKy(string _cmnd)
        {
            DangKy _dangKy = dbs.DangKies.Single(dt => dt.CMND == _cmnd);
            dbs.DangKies.DeleteOnSubmit(_dangKy);
            dbs.SubmitChanges();
        }
        public void SuaDangKy(string _cmnd, string _maPhong, DateTime _ngayDK, DateTime _ngayDi)
        {
            DangKy _dangKy = dbs.DangKies.Single(dt => dt.CMND == _cmnd);
            _dangKy.MaPhong = _maPhong;
            _dangKy.NgayDK = _ngayDK;
            _dangKy.NgayDi = _ngayDi;
            dbs.SubmitChanges();
        }
    }

}
